home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1999
/
MacHack 1999.toast
/
The Hacks
/
DesktopDoubler
/
Nub
/
DisplayManager.c
< prev
next >
Wrap
Text File
|
1999-06-26
|
4KB
|
265 lines
#define DISABLE_LOCAL_CALLTRACE 1 // Set to 1 to disable Call Traces for this file.
#define DISABLE_LOCAL_DEBUG 0 // Set to 1 to disable all debugging for this file.
#include "DebugUtils.h"
#include <Displays.h>
#include <Errors.h>
#include <LowMem.h>
#include "ContextUtils.h"
#include "Display.h"
#include "DisplayManager.h"
DisplayManager::DisplayManager(void)
{
fMainDevice = NULL;
fCloneDevice = NULL;
fDisplayCount = 0;
fCloneDisplay = NULL;
fCurDisplay = NULL;
fMBarTracker = NULL;
fDMNotifierInstalled = false;
}
DisplayManager::~DisplayManager(void)
{
Display *display;
while((display = fDisplayList.Pop()) != NULL)
{
display->Destroy();
delete display;
}
}
OSStatus DisplayManager::Initialize(UInt32 numVirtualDisplays)
{
Display *display;
UInt32 index;
OSStatus err;
// Sanity checks.
dAssert(numVirtualDisplays >= 2);
if (numVirtualDisplays < 2)
numVirtualDisplays = 2;
// Save this for later...
fDisplayCount = numVirtualDisplays;
fMainDevice = GetMainDevice();
fCloneDevice = fMainDevice;
// Create clone display for the main device.
display = new Display(0);
dAssert(display != NULL);
if (display == NULL)
return memFullErr;
err = display->Create(fCloneDevice,NULL,true);
if (err != noErr)
{
dprintf(kDConPrefix "Display::Create failed: %ld",err);
return err;
}
fDisplayList.Append(display);
fCloneDisplay = display;
fCurDisplay = display;
// Create the virtual displays
for (index = 1;index < numVirtualDisplays;index += 1)
{
err = AddDisplay(index);
if (err != noErr)
{
dprintf(kDConPrefix "DisplayManager::AddDisplay failed: %ld",err);
return err;
}
}
fCurDisplay->ShowHide(false);
return noErr;
}
void DisplayManager::Idle(Point where)
{
Display *display;
// Check for display switch.
display = FindDisplay(where);
dAssert(display != NULL);
if (display != GetCurDisplay())
Swap(display);
}
void DisplayManager::Swap(Display *display)
{
// Sanity checks.
dAssert(display != NULL);
if (display == NULL)
return;
// Check for easy out.
if (display == fCurDisplay)
return;
dprintf(kDConPrefix "Swap: from = $%08lX, to = $%08lX\n",fCurDisplay,display);
fCurDisplay->ShowHide(true);
fCurDisplay = display;
fCurDisplay->ShowHide(false);
}
void DisplayManager::Refresh(void)
{
fCurDisplay->ShowHide(true);
fCurDisplay->ShowHide(false);
}
void DisplayManager::MBarClick(Display *display,Point where)
{
Point offset,base;
EvQElPtr event;
OSStatus err;
// Sanity checks.
dAssert(display != NULL);
if (display == NULL)
return;
// Post a mouseDown in the real menu bar.
err = PPostEvent(mouseDown,0,&event);
dAssert(err == noErr);
if (err == noErr)
{
base = *(Point*)&(GetMainDevice())[0]->gdRect;
offset = display->GetOffset();
event->evtQWhere.h = where.h - (offset.h - base.h);
event->evtQWhere.v = where.v - (offset.v - base.v);
}
}
void DisplayManager::SetMBarTracker(Point where,Boolean track)
{
if (track)
{
fMBarTracker = FindDisplay(where);
dAssert(fMBarTracker != NULL);
}
else
fMBarTracker = NULL;
}
void DisplayManager::OffsetMBarMouse(Point *where)
{
Point offset,base;
if (fMBarTracker != NULL)
{
base = *(Point*)&(GetMainDevice())[0]->gdRect;
offset = fMBarTracker->GetOffset();
where->h = where->h - (offset.h - base.h);
where->v = where->v - (offset.v - base.v);
}
}
Display *DisplayManager::FindDisplay(Point where)
{
Display *display;
display = fDisplayList.GetFirst();
for (;display != NULL;display = display->next)
if (display->Contains(where))
return display;
return NULL;
}
Display *DisplayManager::FindDisplay(DisplayIDType displayID)
{
Display *display;
display = fDisplayList.GetFirst();
for (;display != NULL;display = display->next)
if (displayID == display->GetDisplayID())
return display;
return NULL;
}
#if 0
#pragma mark -
#endif
OSStatus DisplayManager::AddDisplay(UInt32 index)
{
Display *display;
OSStatus err;
display = new Display(index);
dAssert(display != NULL);
if (display == NULL)
return memFullErr;
err = display->Create(fCloneDevice,NULL,false);
if (err != noErr)
{
dprintf(kDConPrefix "Display::Create failed: %ld",err);
return err;
}
fDisplayList.Push(display);
return noErr;
}